<?php
/**
 * include files & define sth & waiting for run.
 */
#

define('ROOT_PATH',		realpath(dirname(__FILE__)));

//define('MOD_CLI',		PHP_SAPI=='cli'?true:false);
define('MOD_WIN',		DIRECTORY_SEPARATOR=='\\'?true:false);

import('#/core.php');
import('#/lib.php');
import('#/controller.php');

Core::prepro();


/**
 * 加载一个文件/只包含一次
 * 若以"#"为首的字符串$file，认为从fw取数据会自动换为fw路径
 * 同理"$"为应用的目录, "%"为应用模板源码目录
 */
function import($file)
{
	$sfile	=	my_path($file);
	if(!$sfile){
		throw new Exception("[$file] is not exists.");
	}
	
	static $included	=	array();
	if(!isset($included[$sfile]))
	{
		$included[$sfile]	=	1;
		return include($sfile);
	}
}
function my_path($file)
{
	switch(substr($file,0,1))
	{
	case '#':	//fw根目录
		$file	=	ROOT_PATH.substr($file, 1);
		break;
	case '$':	//项目源码目录
		$file	=	SRC_PATH.substr($file, 1);
		break;
	case '%':	//项目模板源码目录
		$file	=	TPL_PATH.'/'.View::theme().'/src'.substr($file, 1);
		break;
	}
	return realpath($file);
}

?>